package com.etime.shuhuiyuan.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.dto.TeacherDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TeacherDtoDao extends BaseMapper<TeacherDto> {

    @Select("<script> "+
            "SELECT t.tecid,t.tecorgid,t.tectitle,t.teclabel,t.tecauditstate,u.usertruename,u.userid,o.orgname,o.orgid FROM teacher t JOIN sysuser u ON t.userid=u.userid"
            +" JOIN organization o ON t.tecorgid=o.orgid"
            +" <where>"
            +" <if test=' usertruename != null and usertruename != \"\" '> AND u.usertruename LIKE #{usertruename}</if>"
            +" </where>"
            +" </script> "
    )
    List<TeacherDto> selectTeacherDtoList(TeacherDto teacherDto,@Param("usertruename") String usertruename);

    //分页查询
@Select("<script>"+
        " SELECT t.tecid,t.tecorgid,t.tectitle,t.teclabel,t.tecauditstate,u.usertruename,u.userid,o.orgname,o.orgid FROM teacher AS t"
        +" JOIN sysuser AS u ON t.userid=u.userid"
        +" JOIN organization AS o ON t.tecorgid=o.orgid"
        +" <where>"
        +" <if test=' state != null'> AND tecauditstate = #{state}</if>"
        +" <if test=' usertruename != null and usertruename != \"\" '> AND u.usertruename LIKE #{usertruename}</if>"
        +" </where>"
        +" </script> ")
    Page<TeacherDto> selectTeacherDtoByPage(Page<TeacherDto> page, TeacherDto teacherDto,@Param("usertruename") String usertruename,@Param("state") Integer state);

    //根据id查询TeacherDto
    @Select("SELECT t.tecid,t.tecorgid,t.tectitle,t.teclabel,t.tecauditstate,u.usertruename,u.userid,o.orgname,o.orgid FROM teacher t JOIN sysuser u ON t.userid=u.userid"
            +" JOIN organization o ON t.tecorgid=o.orgid"
            +" WHERE t.tecid = #{id}")
    TeacherDto selectTeacherDtoById(@Param("id") Integer id);

}
